/**
 * @param {number[]} cost
 * @return {number}
 */
 var minimumCost = function(cost) {
  if(cost.length < 2) return cost.reduce((pre,cur) => pre+cur, 0)
  cost.sort((a,b) => b-a)
  let ans = 0
  let i = 0
  for(; i<cost.length-2; i += 3){
    ans += cost[i] + cost[i+1]
  }
  for(; i<cost.length; i++) ans += cost[i]
  return ans
};